﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace CMS_GYM
{
    class clsReportTemplatesDAO
    {
        #region Attribute
        /// <summary>
        /// Kết nối SQL Server
        /// </summary>
        private CSQLServer sqlServer = new CSQLServer();
        #endregion

        #region GetReportTemplate(int reportTemplate)
        public DataTable GetReportTemplate(int reportTemplate)
        {
            string sql = "sp_GetInfoReportTemplatesById";
            string[] ParameterColection = new string[1];
            Object[] valueofParameter = new Object[1];
            ParameterColection[0] = "@ReportTemplate";
            valueofParameter[0] = reportTemplate;
            DataTable table = sqlServer.readData(sql, ParameterColection, valueofParameter);
            return table;
        }
        #endregion

        #region GetReportTemplate(string reportFileName)
        public DataTable GetReportTemplate(string reportFileName)
        {
            string sql = "sp_GetInfoReportTemplatesByName";
            string[] ParameterColection = new string[1];
            Object[] valueofParameter = new Object[1];
            ParameterColection[0] = "@ReportFileName";
            valueofParameter[0] = reportFileName;
            DataTable table = sqlServer.readData(sql, ParameterColection, valueofParameter);
            return table;
        }
        #endregion

        #region GetReportTemplates()
        public DataTable GetReportTemplates()
        {
            string sql = "sp_GetBangReportTemplates";
            DataTable table = sqlServer.readData(sql);
            return table;
        }
        #endregion

        public int Them(clsReportTemplatesDTO ReportTemplate)
        {
            int i = -1;
            string sql = "sp_InsertReportTemplates";
            string[] ParameterColection = new string[4];
            Object[] valueofParameter = new Object[4];
            ParameterColection[0] = "@ReportTemplateName";
            valueofParameter[0] = ReportTemplate.ReportTemplateName;
            ParameterColection[1] = "@ReportFileName";
            valueofParameter[1] = ReportTemplate.ReportFileName;
            ParameterColection[2] = "@ReportTemplateXml";
            valueofParameter[2] = ReportTemplate.ReportTemplateXml;
            ParameterColection[3] = "@Note";
            valueofParameter[3] = ReportTemplate.Note;

            i = sqlServer.writeData(sql, ParameterColection, valueofParameter);
            return i;
        }

        public int Sua(clsReportTemplatesDTO ReportTemplate)
        {
            int i = -1;
            string sql = "sp_UpdateReportTemplates";
            string[] ParameterColection = new string[5];
            Object[] valueofParameter = new Object[5];
            ParameterColection[0] = "@ReportTemplate";
            valueofParameter[0] = ReportTemplate.ReportTemplate;
            ParameterColection[1] = "@ReportTemplateName";
            valueofParameter[1] = ReportTemplate.ReportTemplateName;
            ParameterColection[2] = "@ReportFileName";
            valueofParameter[2] = ReportTemplate.ReportFileName;
            ParameterColection[3] = "@ReportTemplateXml";
            valueofParameter[3] = ReportTemplate.ReportTemplateXml;
            ParameterColection[4] = "@Note";
            valueofParameter[4] = ReportTemplate.Note;

            i = sqlServer.writeData(sql, ParameterColection, valueofParameter);
            return i;
        }

        public int Xoa(int ReportTemplateId)
        {
            int i = -1;
            string sql = "sp_DeleteReportTemplates";
            string[] ParameterColection = new string[1];
            Object[] valueofParameter = new Object[1];
            ParameterColection[0] = "@ReportTemplate";
            valueofParameter[0] = ReportTemplateId;
            i = sqlServer.writeData(sql, ParameterColection, valueofParameter);
            return i;
        }
    }
}
